package com.tensquare.article.dao;

import com.tensquare.article.pojo.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.article.pojo.Article;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.util.List;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface ArticleDao extends JpaRepository<Article,String>,JpaSpecificationExecutor<Article>{
    /**
     * 审核
     * Modifying增删改操作只要是设计线程安全的都需要加
     * ?1表示参数列表中第一个
     */
    @Modifying
    @Query(value = "update tb_article set state =1 where id=?1",nativeQuery = true)
    public void examine(String id);

    /**
     * 文章点赞
     */
    @Modifying
    @Query(value = "update tb_article set thumbup = thumbup+1 where id=?1",nativeQuery = true)
    public int updateThumbup(String id);
    @Query(value = "select a.id AS id,a.columnid,a.userid,a.title,a.content,a.image,a.createtime,a.updatetime,a.ispublic,a.istop,a.visits,a.thumbup,a.`comment`,a.state,a.channelid,a.url,a.type,u.nickname as nickname from tb_article a left join tensquare_user.tb_user u on u.id = a.userid",nativeQuery = true)
    List<Article> getAll();

    /**
     * 评论Dao
     * @author Administrator
     *
     */

}
